<template>
  <div class="myCard">
    <nav-bar :left-arrow="true" :title='title'></nav-bar>
    <div class="card" v-for="item in card" :key='item.index'>
      <div v-if="!item.effective" class="active">
        <div class="left">
          <p>{{item.title}}</p>
          <span>{{item.effectiveTime}}</span>
        </div>
        <div class="right">
          <div v-if="!item.effective">
            <h2>未过期</h2>
          </div>
          <div v-else>
            <h2>已过期</h2>
          </div>
      </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import NavBar from '@/components/NavBar'
import { myCoupon } from '@/api/mine'
export default {
  name: 'Card',
  components: {
    NavBar
  },
  computed: {
    ...mapGetters([
      'userInfo'
    ])
  },
  data () {
    return {
      title: '我的卡包',
      card: []
    }
  },
  created () {
    // 获取数据
    this.getCard()
  },
  methods: {
    async getCard () {
      const params = {
        userId: this.userInfo.userId
      }
      const { data: res } = await myCoupon(params)
      if (res.data !== null) {
        res.data.forEach(item => {
          if (item.effective === false) {
            this.card.push(item)
          }
        })
      }
    }
  }
}
</script>

<style scoped lang='scss'>
.active{
  width: 90%;
  height: 120px;
  border-radius: 10px;
  background-color: aquamarine;
  margin: 10px 5%;
}
// .active{
//   height: 100%;
//   height: 100%;
//   background-color: aquamarine;
//   border-radius: 10px;
// }
.left{
  float: left;
  padding: 20px;
  p{
    font-size: 16px;
    color: #fff;
  }
  span{
    font-size: 12px;
    color: #fff;
  }
}
.right{
  float: right;
  padding: 20px;

  h2{
    font-size: 20px;
    color: #fff;
  }
}
</style>
